﻿using System;

namespace IterationLife.Extensions.Helpers
{
    /// <summary>
    /// 时间帮助类
    /// </summary>
    public class TimeHelper
    {
        /// <summary>
        /// 间隔描述
        /// </summary>
        /// <param name="endTime">结束时间</param>
        /// <param name="startTime">起始时间</param>
        public static string IntervalDescription(DateTime endTime, DateTime startTime)
        {
            if (endTime.Year > startTime.Year)
                return $"{endTime.Year - startTime.Year}年前";
            if (endTime.Month > startTime.Month)
                return $"{endTime.Month - startTime.Month}月前";
            if (endTime.Date > startTime.Date)
                return $"{endTime.Date - startTime.Date}天前";
            if (endTime.Hour > startTime.Hour)
                return $"{endTime.Hour - startTime.Hour}小时前";
            if (endTime.Minute > startTime.Minute)
                return $"{endTime.Minute - startTime.Minute}分钟前";
            return "刚刚";
        }
    }
}
